home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Collections: MegaDisc
/
MegaDisc 33 (1993-04)(MegaDisc Digital Publishing)(AU)(Disk 2 of 2).zip
/
MegaDisc 33 (1993-04)(MegaDisc Digital Publishing)(AU)(Disk 2 of 2).adf
/
Programming
/
PostScript_IV
/
PostScript_IV
Wrap
Text File
|
1993-04-14
|
19KB
|
640 lines
Learning PostScript
~ Part 4 ~
By Peter Goed
|| 33 ||| 33 ||| 33 ||| 33 ||| 33 ||| 33 ||| 33 ||| 33 ||| 33 ||| 33 ||
Resizing and Repositioning
Transformations
One of the more powerful aspects of PostScript is its ability to support
transformations of the coordinate system. You can literally transform the
underlying page into something very different from that which we have been
working with for the previous three parts of this tutorial.
This is an important concept to understand, when you use transformation
operators, you are changing the size, origin and/or orientation of the
underlying coordinate system. This will in turn, transform the appearance
of anything that is subsequently dr awn on the page.
In this month's tutorial we will examine the three most common kinds of
transformation: scaling, translation and rotation - each of which is
supported by a postscript operator.
The 'scale' operator changes the unit size of either the x or y axis, or
both, without affecting their origin or orientation.
The 'translate' operator moves the origin of the coordinate system to a
new location, while leaving unit size and orientation of the x/y axis
unchanged.
The 'rotate' operator turns the axis of the coordinate system by any
specified angle, without affecting unit size or origin of the axis.
Individually, these are powerful features. Collectively, the ability to
scale, translate, and rotate any text and graphics means that with
PostScript, there is virtually nothing that can't be drawn on a page.
scale
The ability to scale any object to any size is perhaps PostScript's single
most important capability. This scaling gives the language its unique
ability to be used with any raster imaging device of any resolution, for
example from a 300 DPI laser to a 4800 DPI high quality image setter, or in
the future perhaps a 10,000 DPI imaging device.
In tutorial 2 we briefly encountered scaling when we used the 'scalefont'
operator to scale typeface outlines to produce a font of any desired point
size.
Unlike 'scalefont', which requires only one operand to scale typefaces
uniformly along both the x and y axis, the 'scale' operator requires two
operands for scaling any object independently or uniformly along either or
both axis.
See how the instructions below create the same output as that in the code
in part 2 of these tutorials under 'show', but by using a 36 point font and
scaling it uniformly along the x and y axis by a factor of 2 to create a 72
point font.
/Times-BoldItalic findfont scalefont 36 setfont
gsave
72 648 moveto
2 2 scale
(Your Text) show
grestore
showpage
Horizontal scaling
Shown in the following code are three ways to stretch the same 72 point
"Your Text" by scaling it only along the horizontal axis. If you print
this out you will see that at y648, the 2 1 'scale' instruction, which
doubles the size for only the x axis, produces a string that appears too
long for the page.
We can modify this by changing the scale factor for the axis to 1.75, as
at y504; or better still, by leaving the scale factor at 2 and using
'ashow' to draw the individual characters closer together as at y360.
/Times-BoldItalic findfont 72 scalefont setfont
gsave
72 648 moveto
2 1 scale
(Your Text) show
grestore
gsave
72 504 moveto
1.75 1 scale
(Your Text) show
grestore
gsave
72 360 moveto
2 1 scale
-5 0 (Your Text) ashow
grestore
showpage
Vertical scaling
Scaling text in the vertical direction produces an interesting change of
pace from the fonts we are accustomed to seeing. If you print out the
following code, notice how scaling a 72 point font by a factor of 1.5
produces uppercase characters that are exactly one inch tall. Remember
that point sizes allow for descenders as well as some white space above and
below the characters.
/Times-Bold findfont 72 scalefont
gsave
72 648 moveto
1 1 scale
-5 0 (Your Text 1.0) ashow
grestore
gsave
72 504 moveto
1 1.5 scale
-5 0 (Your Text 1.5) ashow
grestore
gsave
72 432 moveto
1 .5 scale
-5 0 (Your Text .5) ashow
grestore
gsave
72 288 moveto
1 2 scale
-5 0 (Your Text 2.0) ashow
grestore
gsave
72 72 moveto
1 3 scale
-5 0 (Your Text 3.0) ashow
grestore
showpage
Emphasizing and Fitting Text
Vertical scaling is useful for emphasizing certain aspects of a graphic
(as in the word sale in the following page description), and also for
fitting into a width that is determined by the other elements of the
graphic (as in the last part of the description "THURSDAY, MAY 5").
/Helvetica findfont 72 scalefont setfont
72 648 moveto
(PRE-SEASON) show
gsave
/Times-Bold findfont
144 scalefont setfont
72 191 moveto
1.25 4 scale
(SALE) show
grestore
72 72 moveto
.72 1 scale
(THURSDAY, MAY 5) show
showpage
NOTE:- In the last line of the description we were able to use the
original 72 point Helvetica font without specifying it explicitly. We used
'gsave' and 'grestore' to temporarily select the 144 point Times-Bold font
and then restored the 72 point Helvetica font as the current font.
A Word of Caution
When using the 'scale' operator, ensure that you use the 'gsave' and
'grestore' operators before and after it if you don't want succeeding
instructions to be affected. This applies to object size as well as
location on the page.
The instructions below show how text intended for coordinates 144, 288 is
moved to 72, 144 due to the previous 'scale' instruction. Print it out and
you will get the message clearly.
/Times-BoldItalic findfont 72 scalefont setfont
144 576 moveto
(Amiga One) show
144 432 moveto
.5 .5 scale
(Amiga Two) show
144 288 moveto
(Amiga Three) show % Because of the .5 .5 scale used above
% you will now have changed your page
% coordinates to 50% of your intended size,
% but not your type size, because it is
% still .5 .5 scale of the 72 point font.
showpage
As a general rule you should use 'gsave' and 'grestore' before and after
issuing 'scale' instructions, and do a 'moveto' to the desired location
before scaling.
Reflections
You can also use 'scale' to invert any object by specifying negative
values for either the x or y axis operands. Negative x inverts the object
on the horizontal axis (right to left), and negative y inverts the object
bottom to top. When both values are negative, the object is inverted in
both directions.
/Helvetica-Bold findfont 36 scalefont setfont
gsave
306 396 moveto
1 3 scale
(Amiga-1) show
grestore
gsave
306 396 moveto
-1 3 scale
(Amiga-2) show
grestore
gsave
306 396 moveto
1 -3 scale
(Amiga-3) show
grestore
gsave
306 396 moveto
-1 -3 scale
(Amige-4) show
grestore
showpage
Mirror
The same technique can be used effectively to create some interesting
effects using the 'setgray' operator, as shown in the following code.
/Helvetica-Bold findfont 144 scalefont setfont
gsave
54 396 moveto
1 3 scale
(PETER) show
grestore
gsave
54 396 moveto
.8 setgray
1 -3 scale
(PETER) show
grestore
showpage
translate
Where 'scale' is used to resize elements of a page description, the
'translate' operator is used for repositioning certain elements of a page
description, or an entire page description. It moves the origin of the
entire page from the lower-left corner to the x/y coordinates you specify
in the operands for 'translate'.
To demonstrate the change, we'll compare two similarly produced examples.
For the first take our by now familiar instructions to produce "Your Text",
this time at coordinates 72, 72.
/Times-BoldItalic findfont 72 scalefont setfont
72 72 moveto
(Your Text) show
showpage
Repositioning
You can achieve the same results as in the previous example with the
following instructions.
/Times-BoldItalic findfont 72 scalefont setfont
72 72 translate
0 0 moveto
(Your Text) show
showpage
As you can see when you print out this and the previous examples, they are
both printed at the same location - with respect to the original coordinate
system, but because the 72, 72 'translate' instruction displaces the origin
of the underlying coordinate system, the moveto instruction is vastly
different.
Thus 'translate' provides the ability to locate any set of instructions
anywhere on the page, making it extremely easy to relocate PostScript
routines.
Repetition
We can repeat the same result from the previous example anywhere on the
page by simply repeating the 'translate' instruction. Because the 'scale'
and 'translate' instructions are not enclosed in 'gsave' and 'grestore',
the effects are cumulative, moving up the page 72 points each time.
/Times-BoldItalic findfont 72 scalefont setfont
72 72 translate
0 0 moveto
(Your Text) show
0 72 translate
0 0 moveto
(Your Text) show
0 72 translate
0 0 moveto
(Your Text) show
% Etc.
showpage
Similarity
With 'translate', we can re-use the same drawing routines, positioning the
results at different coordinates.
Compare the following instructions with those in tutorial 3 headed
Fancy Text within a Shadow Box. Because of
the 10 -10 'translate' in the shadow box routine below, we can initiate all
three boxes with the same "36 576 moveto" instruction.
% Shadow box
gsave
10 -10 translate
46 576 moveto % Replaces 46 566 moveto
540 0 rlineto 0 100 rlineto -540 0 rlineto
closepath fill
grestore
% Background box
gsave
36 576 moveto
1 setgray
540 0 rlineto 0 100 rlineto -540 0 rlineto
closepath fill
grestore
% Outline box
36 576 moveto
2 setlinewidth
540 0 rlineto 0 100 rlineto -540 0 rlineto
closepath stroke
showpage
The ability to reuse routines as "procedures" is an important part of
PostScript and will be explored more fully in tutorial 7.
Enlarged Diamond
Using the homework example from tutorial 1 (if you did not do it you will
now need to pull your finger out and go and have a bash at it), where we
created a symmetrical diamond, we can use the 'translate' operator to
permanently reposition an entire page so that the effect of scaling will
have no effect on the position of certain objects on the page.
By using this example to scale the diamond using "1.5 1.5 scale", the
larger diamond moves off the page.
% Original diamond
486 396 moveto
-180 180 rlineto -180 -180 rlineto 180 -180 rlineto
closepath
stroke
% Scaled diamond
486 396 moveto
1.5 1.5 scale
-180 180 rlineto -180 -180 rlineto 180 -180 rlineto
closepath
stroke
showpage
Centre of Origin
Had we planned ahead when we drew the initial diamond we could have drawn
it in such a way that it could be easily resized. One way to accomplish
this would be by repositioning the origin at the centre of the page using
the following instruction.
306 396 translate
Centre Page Grid
Relocating the origin at the centre of the page allows us to draw diamonds
of any size, repeating all instructions except for the one that scales each
diamond.
306 396 translate
gsave
1 1 scale
180 0 moveto
-180 180 rlineto -180 -180 rlineto 180 -180 rlineto
closepath stroke
grestore
gsave
1.5 1.5 scale
180 0 moveto
-180 180 rlineto -180 -180 rlineto 180 -180 rlineto
closepath stroke
grestore
gsave
.5 .5 scale
180 0 moveto
-180 180 rlineto -180 -180 rlineto 180 -180 rlineto
closepath stroke
grestore
showpage
Note how the origin for both the x and y axis is now in the centre of the
page and how we used negative values to position elements that are to the
left of or below this new point of origin. The new origin is reflected in
the x and y values that accomp any the new grid.
Scale and Translate
You can combine the 'translate' and 'scale' operators to perform specific
tasks such as reducing the size of a full-page description to one half of
its normal size.
153 198 translate % 612/4 and 792/4
.5 .5 scale % Half size page
0 0 moveto
612 0 rlineto 0 792 rlineto -612 0 rlineto
closepath stroke
showpage
We first translate the point of origin one quarter page right and up from
the original point of origin, then scale both axis by one half. Note that
the rectangle that we drew is for a full 612 by 792 point page, scaled by
one half.
'rotate'
You can use 'rotate' to reorient the page without affecting the page size
or origin. The 'rotate' operator turns the grid counter-clockwise the
number of degrees specified in the single operand.
As an example, let us show a single line of text perpendicular to text on
the rest of the page, by rotating the coordinate system 90 degrees
(temporarily - by using 'gsave' and 'grestore') before stroking the text
outlines in normal orientation.
/Times-BoldItalic findfont 72 scalefont setfont
gsave
72 72 moveto
90 rotate
(Brisbane) true charpath
grestore
72 72 moveto
(Brisbane) true charpath
showpage
Negative Rotation
A negative value for the 'rotate' operand rotates the page in a clockwise
direction.
/Times-Roman findfont 72 scalefont setfont
306 396 translate
0 0 moveto
-45 rotate
(Brisbane) show
showpage
Cumulative Rotation
Like 'scale' and 'rotate' the effects of successive 'rotate' operations
are cumulative. In this example we permanently 'translate' the origin to
the centre of the page, then 'rotate' a fixed number of degrees.
/Times-Roman findfont 50 scalefont setfont
306 396 translate
-90 rotate
90 rotate
0 0 moveto
(0 Brisbane) show
90 rotate
0 0 moveto
(90 Brisbane) show
90 rotate
0 0 moveto
(180 Brisbane) show
90 rotate
0 0 moveto
(270 Brisbane) show
showpage
'translate' and 'rotate'
We can also combine 'translate' and 'rotate' to change the origin and
orientation of the entire page for all subsequent operations --- a truly
useful tool for changing a page to "landscape" orientation.
The landscape orientation, which prints perpendicular to the normal
vertical page orientation, is popular in desktop publishing for creating
three column brochures and A4 magazines.
In this two step procedure, the first step is to translate the origin from
the lower left corner to the lower right corner by the following
instruction.
612 0 translate
Landscape Orientation
Next a "90 rotate" instruction reorients the page along the vertical axis,
so that the lower right corner becomes the new lower left corner.
612 0 translate
90 rotate
/Times-BoldItalic findfont 72 scalefont setfont
72 72 moveto
(Brisbane Landscape) show
showpage
And voila, we have created a landscape page.
'translate', 'rotate' and 'scale'
Finally we can combine all three transformation operators in one program.
612 0 translate
90 rotate
/Helvetica-Bold findfont 84 scalefont setfont
gsave
396 190 moveto
1 4 scale
(DEBATE) show
grestore
gsave
.8 setgray
396 190 moveto
-1 4 scale
(DEBATE) show
grestore
/Times-Bold findfont 72 scalefont setfont
54 504 moveto
.8 setgray
(FORBES v) show
0 setgray
(s FULLER) show
/Helvetica-Bold findfont 32 scalefont setfont
36 72 moveto
.8 setgray
1 2 scale
(CIVIC AUDITORIUM, FRI) show
0 setgray
(DAY, MAY 24, 7:30 ) show
/Helvetica-Bold findfont 30 scalefont setfont
0 6 moveto
(p.m.) show
showpage
Well that is it for another month, the teacher is too tired from all the
keyboard input to set an assignment this month, if you do not feel
comfortable at this point, revision of earlier sessions will definitely
help alleviate the problem.........See you next month!!!!!!!
|| 33 ||| 33 ||| 33 ||| 33 ||| 33 ||| 33 ||| 33 ||| 33 ||| 33 ||| 33 ||